package biz.datalk.industrialland.admin.modules.system.controller;

import biz.datalk.industrialland.common.encrypt.annotation.RSAES;
import biz.datalk.industrialland.common.log.aspect.annotation.SysLog;
import biz.datalk.industrialland.common.log.def.OptEnum;
import biz.datalk.industrialland.common.result.UnifyResult;
import biz.datalk.industrialland.admin.modules.system.pojo.dto.SysRoleFunctionDTO;
import biz.datalk.industrialland.admin.modules.system.pojo.vo.SysRoleFunctionVO;
import biz.datalk.industrialland.admin.modules.system.service.ISysRoleFunctionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 *
 *
 * @author tarofang@163.com
 * @date 2020-06-01
 *
 */
@RestController
@RequestMapping("/sys/roleFunction")
public class SysRoleFunctionController {

    private final ISysRoleFunctionService sysRoleFunctionService;

    @Autowired
    public SysRoleFunctionController(ISysRoleFunctionService sysRoleFunctionService) {
        this.sysRoleFunctionService = sysRoleFunctionService;
    }

    @RSAES
    @PostMapping(value = "/roleFuncs", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_FUNC_10807)
    public UnifyResult tree(@RequestBody SysRoleFunctionDTO sysRoleFunctionDTO) {
        List<SysRoleFunctionVO> funcs = sysRoleFunctionService.roleFuncs(sysRoleFunctionDTO);

        List<Long> funcIds = new ArrayList<>();
        for (SysRoleFunctionVO func : funcs) {
            funcIds.add(func.getFunctionId());
        }

        return UnifyResult.success().setData(funcIds);
    }

    @RSAES
    @PostMapping(value = "/roleFuncAuth", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @SysLog(OptEnum.LAND_FUNC_10808)
    public UnifyResult roleFuncAuth(@RequestBody SysRoleFunctionDTO sysRoleFunctionDTO) {
        sysRoleFunctionService.roleFuncAuth(sysRoleFunctionDTO);
        return UnifyResult.success();
    }


}
